package day10_poly.demo08_Exception;

public class Student {
    private int age;//1-120
    public int getAge() {
        return age;
    }
    //赋值范围超出1-120,逻辑上有错误
    //自定义异常:java虽然提供了一些异常类,不能满足所有的需求
    public void setAge(int age) {
        if(age<1 ||age>120){
            //控制台弹出StudentAgeException
            throw new StudentAgeException("超出1-120");
        }else {
            this.age=age;
        }
    }
}
